from Entities.Calendars.SimpleCalendar import SimpleCalendar
from Entities.Calendars.RepeatingHoliday import RepeatingHoliday
from Entities.Calendars.WeekdayHoliday import WeekdayHoliday
from Entities.Calendars.SimpleHoliday import SimpleHoliday

from EntitiesTest.Calendars.CalendarTest import CalendarTest

import datetime
from datetime import timedelta
import unittest

class SimpleCalendarTest (CalendarTest):
    
    def setUp (self):
        self.cal = SimpleCalendar (code='NY', name='New York', holidays=[WeekdayHoliday.Saturday(), WeekdayHoliday.Sunday(),SimpleHoliday("1",2011,2,22),RepeatingHoliday ("2",2,21)])
        
    def testWeekends (self):
        oneday = timedelta(days=1)
        when = datetime.date (2011,3,7) # Monday
        for i in xrange (0,7):
            self.assert_ (self.cal.isholiday(when) == (i in [5,6]))
            when = when + oneday
            
    def testActuals (self):
        self.assertTrue  (self.cal.isholiday (datetime.date(2011,2,22)))
        self.assertFalse (self.cal.isholiday (datetime.date(2011,2,23)))   
                 
    def testRepeating (self):
        self.assertTrue  (self.cal.isholiday (datetime.date(2011,2,21)))
        self.assertTrue  (self.cal.isholiday (datetime.date(2012,2,21)))
        self.assertFalse (self.cal.isholiday (datetime.date(2011,3,22)))
        self.assertFalse (self.cal.isholiday (datetime.date(2012,3,22)))
            
def Suite ():
    return unittest.TestLoader().loadTestsFromTestCase(SimpleCalendarTest)
        
if __name__ == '__main__':
    unittest.TextTestRunner().run(Suite())

            
        
